package top.shen33.yang.base.validator;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;

/**
 * Created by Administrator on 2017-11-23.
 */
public class ValidatorUtil {


    private static Validator validator= Validation.buildDefaultValidatorFactory().getValidator();


    public static <T>ValidatorR validIt(T entity){


        Set<ConstraintViolation<T>> validateSet = validator.validate(entity);

        ValidatorR validatorR=new ValidatorR();
        if (!validateSet.isEmpty()) {

            validatorR.setErrFlag(true);

            for (ConstraintViolation<T> cv : validateSet) {
//                System.out.println(cv.getMessage());
                validatorR.setErrMsg(cv.getMessage());
                return  validatorR;
            }
        }

        return validatorR;
    }


}
